package com.lcx.security.main;

import com.lcx.security.config.StreamConfig;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.io.File;
import java.util.Calendar;

// 每次项目启动成功后，立即执行推流测试
@Component
public class RtspToRtmpStart implements CommandLineRunner {

    @Override
    public void run(String... args) throws Exception {
        File file = new File(StreamConfig.FILE_PATH);
        if (!file.exists()){
            file.mkdir();
        }
        Calendar instance = Calendar.getInstance();
        int hour = instance.get(Calendar.HOUR_OF_DAY);
//        String fileName = StreamConfig.FILE_PATH+hour+"_1.mp4";
        String fileName = StreamConfig.FILE_PATH+instance.get(Calendar.DAY_OF_MONTH)+":"+hour+".mp4";
        File mp4 = new File(fileName);
        if (mp4.exists()){
            mp4.delete();
        }
        try {
            FFmpegCMD.rtspToMP4(fileName);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
